/*
  Copyright � 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  ThanhNam ERP Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using VINETLIFE.DO;
/// <summary>
/// Summary description for cmsPaymentMethodDAL
/// </summary>
namespace VINETLIFE.DAL
{

    public class cmsPaymentMethodDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public cmsPaymentMethodDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(cmsPaymentMethodDO objcmsPaymentMethodDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsPaymentMethod_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@PaymentCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPaymentMethodDO.PaymentCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@PaymentText", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPaymentMethodDO.PaymentText;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsPaymentMethodDO.CreatedDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedById", SqlDbType.Int);
            Sqlparam.Value = objcmsPaymentMethodDO.CreatedById;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LastSaveDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsPaymentMethodDO.LastSaveDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LastModifiedById", SqlDbType.Int);
            Sqlparam.Value = objcmsPaymentMethodDO.LastModifiedById;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Note", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPaymentMethodDO.Note;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Icon", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPaymentMethodDO.Icon;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@UnpaidIcon", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPaymentMethodDO.UnpaidIcon;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@PaidIcon", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPaymentMethodDO.PaidIcon;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SystemStatus", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPaymentMethodDO.SystemStatus;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderSequence", SqlDbType.Int);
            Sqlparam.Value = objcmsPaymentMethodDO.OrderSequence;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(cmsPaymentMethodDO objcmsPaymentMethodDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsPaymentMethod_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@PaymentMethodId", SqlDbType.Int);
            Sqlparam.Value = objcmsPaymentMethodDO.PaymentMethodId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@PaymentCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPaymentMethodDO.PaymentCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@PaymentText", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPaymentMethodDO.PaymentText;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsPaymentMethodDO.CreatedDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedById", SqlDbType.Int);
            Sqlparam.Value = objcmsPaymentMethodDO.CreatedById;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LastSaveDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsPaymentMethodDO.LastSaveDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LastModifiedById", SqlDbType.Int);
            Sqlparam.Value = objcmsPaymentMethodDO.LastModifiedById;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Note", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPaymentMethodDO.Note;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Icon", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPaymentMethodDO.Icon;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@UnpaidIcon", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPaymentMethodDO.UnpaidIcon;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@PaidIcon", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPaymentMethodDO.PaidIcon;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SystemStatus", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPaymentMethodDO.SystemStatus;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderSequence", SqlDbType.Int);
            Sqlparam.Value = objcmsPaymentMethodDO.OrderSequence;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(cmsPaymentMethodDO objcmsPaymentMethodDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsPaymentMethod_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@PaymentMethodId", SqlDbType.Int);
            Sqlparam.Value = objcmsPaymentMethodDO.PaymentMethodId;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsPaymentMethod_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public cmsPaymentMethodDO Select(cmsPaymentMethodDO objcmsPaymentMethodDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsPaymentMethod_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@PaymentMethodId", SqlDbType.Int);
            Sqlparam.Value = objcmsPaymentMethodDO.PaymentMethodId;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["PaymentMethodId"]))
                    objcmsPaymentMethodDO.PaymentMethodId = Convert.ToInt32(dr["PaymentMethodId"]);
                if (!Convert.IsDBNull(dr["PaymentCode"]))
                    objcmsPaymentMethodDO.PaymentCode = Convert.ToString(dr["PaymentCode"]);
                if (!Convert.IsDBNull(dr["PaymentText"]))
                    objcmsPaymentMethodDO.PaymentText = Convert.ToString(dr["PaymentText"]);
                if (!Convert.IsDBNull(dr["CreatedDate"]))
                    objcmsPaymentMethodDO.CreatedDate = Convert.ToDateTime(dr["CreatedDate"]);
                if (!Convert.IsDBNull(dr["CreatedById"]))
                    objcmsPaymentMethodDO.CreatedById = Convert.ToInt32(dr["CreatedById"]);
                if (!Convert.IsDBNull(dr["LastSaveDate"]))
                    objcmsPaymentMethodDO.LastSaveDate = Convert.ToDateTime(dr["LastSaveDate"]);
                if (!Convert.IsDBNull(dr["LastModifiedById"]))
                    objcmsPaymentMethodDO.LastModifiedById = Convert.ToInt32(dr["LastModifiedById"]);
                if (!Convert.IsDBNull(dr["Note"]))
                    objcmsPaymentMethodDO.Note = Convert.ToString(dr["Note"]);
                if (!Convert.IsDBNull(dr["Icon"]))
                    objcmsPaymentMethodDO.Icon = Convert.ToString(dr["Icon"]);
                if (!Convert.IsDBNull(dr["UnpaidIcon"]))
                    objcmsPaymentMethodDO.UnpaidIcon = Convert.ToString(dr["UnpaidIcon"]);
                if (!Convert.IsDBNull(dr["PaidIcon"]))
                    objcmsPaymentMethodDO.PaidIcon = Convert.ToString(dr["PaidIcon"]);
                if (!Convert.IsDBNull(dr["SystemStatus"]))
                    objcmsPaymentMethodDO.SystemStatus = Convert.ToString(dr["SystemStatus"]);
                if (!Convert.IsDBNull(dr["OrderSequence"]))
                    objcmsPaymentMethodDO.OrderSequence = Convert.ToInt32(dr["OrderSequence"]);

            }
            return objcmsPaymentMethodDO;
        }
        public cmsPaymentMethodDO SelectByPaymentCode(string paymentCode)
        {
            cmsPaymentMethodDO objcmsPaymentMethodDO = new cmsPaymentMethodDO();
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsPaymentMethod_GetByPaymentCode";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@PaymentCode", SqlDbType.NVarChar);
            Sqlparam.Value = paymentCode;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["PaymentMethodId"]))
                    objcmsPaymentMethodDO.PaymentMethodId = Convert.ToInt32(dr["PaymentMethodId"]);
                if (!Convert.IsDBNull(dr["PaymentCode"]))
                    objcmsPaymentMethodDO.PaymentCode = Convert.ToString(dr["PaymentCode"]);
                if (!Convert.IsDBNull(dr["PaymentText"]))
                    objcmsPaymentMethodDO.PaymentText = Convert.ToString(dr["PaymentText"]);
                if (!Convert.IsDBNull(dr["CreatedDate"]))
                    objcmsPaymentMethodDO.CreatedDate = Convert.ToDateTime(dr["CreatedDate"]);
                if (!Convert.IsDBNull(dr["CreatedById"]))
                    objcmsPaymentMethodDO.CreatedById = Convert.ToInt32(dr["CreatedById"]);
                if (!Convert.IsDBNull(dr["LastSaveDate"]))
                    objcmsPaymentMethodDO.LastSaveDate = Convert.ToDateTime(dr["LastSaveDate"]);
                if (!Convert.IsDBNull(dr["LastModifiedById"]))
                    objcmsPaymentMethodDO.LastModifiedById = Convert.ToInt32(dr["LastModifiedById"]);
                if (!Convert.IsDBNull(dr["Note"]))
                    objcmsPaymentMethodDO.Note = Convert.ToString(dr["Note"]);
                if (!Convert.IsDBNull(dr["Icon"]))
                    objcmsPaymentMethodDO.Icon = Convert.ToString(dr["Icon"]);
                if (!Convert.IsDBNull(dr["UnpaidIcon"]))
                    objcmsPaymentMethodDO.UnpaidIcon = Convert.ToString(dr["UnpaidIcon"]);
                if (!Convert.IsDBNull(dr["PaidIcon"]))
                    objcmsPaymentMethodDO.PaidIcon = Convert.ToString(dr["PaidIcon"]);
                if (!Convert.IsDBNull(dr["SystemStatus"]))
                    objcmsPaymentMethodDO.SystemStatus = Convert.ToString(dr["SystemStatus"]);
                if (!Convert.IsDBNull(dr["OrderSequence"]))
                    objcmsPaymentMethodDO.OrderSequence = Convert.ToInt32(dr["OrderSequence"]);

            }
            return objcmsPaymentMethodDO;
        }
        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsPaymentMethod_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrcmsPaymentMethodDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    cmsPaymentMethodDO objcmsPaymentMethodDO = new cmsPaymentMethodDO();
                    if (!Convert.IsDBNull(dr["PaymentMethodId"]))
                        objcmsPaymentMethodDO.PaymentMethodId = Convert.ToInt32(dr["PaymentMethodId"]);
                    if (!Convert.IsDBNull(dr["PaymentCode"]))
                        objcmsPaymentMethodDO.PaymentCode = Convert.ToString(dr["PaymentCode"]);
                    if (!Convert.IsDBNull(dr["PaymentText"]))
                        objcmsPaymentMethodDO.PaymentText = Convert.ToString(dr["PaymentText"]);
                    if (!Convert.IsDBNull(dr["CreatedDate"]))
                        objcmsPaymentMethodDO.CreatedDate = Convert.ToDateTime(dr["CreatedDate"]);
                    if (!Convert.IsDBNull(dr["CreatedById"]))
                        objcmsPaymentMethodDO.CreatedById = Convert.ToInt32(dr["CreatedById"]);
                    if (!Convert.IsDBNull(dr["LastSaveDate"]))
                        objcmsPaymentMethodDO.LastSaveDate = Convert.ToDateTime(dr["LastSaveDate"]);
                    if (!Convert.IsDBNull(dr["LastModifiedById"]))
                        objcmsPaymentMethodDO.LastModifiedById = Convert.ToInt32(dr["LastModifiedById"]);
                    if (!Convert.IsDBNull(dr["Note"]))
                        objcmsPaymentMethodDO.Note = Convert.ToString(dr["Note"]);
                    if (!Convert.IsDBNull(dr["Icon"]))
                        objcmsPaymentMethodDO.Icon = Convert.ToString(dr["Icon"]);
                    if (!Convert.IsDBNull(dr["UnpaidIcon"]))
                        objcmsPaymentMethodDO.UnpaidIcon = Convert.ToString(dr["UnpaidIcon"]);
                    if (!Convert.IsDBNull(dr["PaidIcon"]))
                        objcmsPaymentMethodDO.PaidIcon = Convert.ToString(dr["PaidIcon"]);
                    if (!Convert.IsDBNull(dr["SystemStatus"]))
                        objcmsPaymentMethodDO.SystemStatus = Convert.ToString(dr["SystemStatus"]);
                    if (!Convert.IsDBNull(dr["OrderSequence"]))
                        objcmsPaymentMethodDO.OrderSequence = Convert.ToInt32(dr["OrderSequence"]);
                    arrcmsPaymentMethodDO.Add(objcmsPaymentMethodDO);
                }
            }
            return arrcmsPaymentMethodDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsPaymentMethod_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectToCart()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsPaymentMethod_GetToCart";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }


        #endregion

    }

}
